﻿/*
 * Project: IV:MP GUI Editor (http://code.google.com/p/ivmp-gui-editor)
 * Code license: GNU Lesser GPL (http://www.gnu.org/copyleft/lesser.html)
 * 
 * Authors: CrackHD
 * Description: A class for managing global application resources.
 */


using System;
using System.Globalization;
using System.Reflection;
using System.Threading;
using System.Windows.Media.Imaging;

namespace IvmpEditor
{
    // FIXME

    public static class ResourceManager
    {
        static BitmapSource m_imgConstant;
        public static BitmapSource ImageConstant
        {
            get
            {
                if (m_imgConstant == null)
                    m_imgConstant = LoadBitmapFromResource("Resources/constant.png");
                return m_imgConstant;
            }
        }

        static BitmapSource m_imgFunction;
        public static BitmapSource ImageFunction
        {
            get
            {
                if (m_imgFunction == null)
                    m_imgFunction = LoadBitmapFromResource("Resources/function.png");
                return m_imgFunction;
            }
        }

        public static BitmapImage LoadBitmapFromResource(string pathInApplication, Assembly assembly = null)
        {
            if (assembly == null)
            {
                assembly = Assembly.GetCallingAssembly();
            }

            if (pathInApplication[0] == '/')
            {
                pathInApplication = pathInApplication.Substring(1);
            }
            return new BitmapImage(new Uri(@"pack://application:,,,/" + assembly.GetName().Name + ";component/" + pathInApplication, UriKind.Absolute));
        }
        public static bool LocalizeThread(Thread trd, string uiCulture)
        {
            // Change UI culture (language) specified in settings
            trd.CurrentUICulture = CultureInfo.GetCultureInfo(uiCulture);

            // This is hack to use a dot instead of a commafor 'CurrencyDecimalSeparator',
            // because Squirrel's separator for doubles is a dot.
            var en_US = new CultureInfo("en-us"); // culture where we get number format
            var culture = trd.CurrentCulture.Clone() as CultureInfo;
            culture.NumberFormat = en_US.NumberFormat;
            trd.CurrentCulture = culture;

            return true;
        }
    }
}
